package com.atguigu.dga.ds.service.impl;

import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.ds.mapper.TDsTaskInstanceMapper;
import com.atguigu.dga.ds.service.TDsTaskInstanceService;
import com.atguigu.dga.meta.bean.TableMetaInfo;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2023-07-03
 */
@Service
@DS("ds")
public class TDsTaskInstanceServiceImpl extends ServiceImpl<TDsTaskInstanceMapper, TDsTaskInstance> implements TDsTaskInstanceService {

    @Override
    public List<TDsTaskInstance> getTaskInstanceListForAssess(String assessDate, List<TableMetaInfo> tableMetaInfoList) {
        List<String> tableNameList= tableMetaInfoList.stream()
                .map(tableMetaInfo-> tableMetaInfo.getSchemaName()+"."+tableMetaInfo.getTableName())
                .collect(Collectors.toList());


        QueryWrapper<TDsTaskInstance> queryWrapper = new QueryWrapper<TDsTaskInstance>().eq("date_format(submit_time,'%Y-%m-%d')", assessDate)
                .in("name", tableNameList);

        List<TDsTaskInstance> taskInstanceList = list(queryWrapper);

        return taskInstanceList;
    }
}
